package com.aodonghao.web.controller;

import com.aodonghao.domain.Student;
import com.aodonghao.service.StudentService;
import com.aodonghao.vo.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;
    @GetMapping("/student")
    public ResultInfo findAll(){
        List<Student> all = studentService.findAll();
        return ResultInfo.success(all);
    }
    @PostMapping("/student")
    public ResultInfo save(@RequestBody Student student){
        studentService.save(student);
        return ResultInfo.success(null);
    }
    @GetMapping("/student/{number}")
    public ResultInfo findByNumber(@PathVariable("number") String number){
      Student  stu=studentService.findByNumber(number);
      return ResultInfo.success(stu);
    }
    @PutMapping("/student")
    public ResultInfo update(@RequestBody Student student){
      studentService.update(student);
      return ResultInfo.success(null);
    }
    @DeleteMapping("/student/{number}")
    public ResultInfo delete(@PathVariable("number") String number){
        studentService.delete(number);
        return ResultInfo.success(null);
    }
}
